package com.sikaryofficial.backend.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sikaryofficial.backend.annotation.TenantFilter;
import com.sikaryofficial.backend.config.TenantFilterProperties;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleAssociateListReq;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleAuditListReq;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleBrandSpecialListReq;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleOwnerListReq;
import com.sikaryofficial.backend.domain.dto.req.information.TopicListReq;
import com.sikaryofficial.backend.domain.dto.resp.information.ArticleGetLikesDTO;
import com.sikaryofficial.backend.domain.dto.resp.information.TopicBackendDTO;
import com.sikaryofficial.backend.domain.dto.resp.information.TopicDTO;
import com.sikaryofficial.backend.domain.entity.Article;
import com.sikaryofficial.backend.domain.vo.infomation.ArticleStatisticsVO;
import com.sikaryofficial.backend.mapper.ArticleMapper;
import com.sikaryofficial.backend.service.IArticleService;
import com.sikaryofficial.common.core.constant.BrandEnum;
import com.sikaryofficial.common.security.utils.SecurityUtils;
import com.sikaryofficial.system.api.model.infomation.ArticleAssociateResp;
import com.sikaryofficial.system.api.model.infomation.ArticleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.sikaryofficial.backend.constant.MyStatisticsTypeEnum.LIKES_ARTICLE;

/**
 * 文章Service业务层处理
 *
 * @author qinjinyuan
 * @date 2024-04-10
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private TenantFilterProperties tenantFilterProperties;

    /**
     * 文章分页列表
     *
     * @param customerPage
     * @param req
     * @return
     */
    @Override
    @TenantFilter
    public IPage<TopicDTO> topicList(Page<TopicDTO> customerPage, TopicListReq req) {
        Integer tenantId = tenantFilterProperties.getTenantByBrand(SecurityUtils.getBrand());
        req.setTenantId(tenantId);
        return articleMapper.topicList(customerPage, req);
    }

    @Override
    public IPage<ArticleDTO> articleList(Page<ArticleDTO> customerPage, ArticleAuditListReq req) {
        return articleMapper.articleList(customerPage, req);
    }

    @Override
    @TenantFilter
    public IPage<TopicBackendDTO> topicBackendList(Page<TopicBackendDTO> customerPage, TopicListReq req) {
        Integer tenantId = tenantFilterProperties.getTenantByBrand(BrandEnum.HISMK.getCode());
        req.setTenantId(tenantId);
        return articleMapper.topicBackendList(customerPage, req);
    }

    /**
     * 个人中心文章列表
     *
     * @param customerPage
     * @return
     */
    @Override
    public IPage<ArticleDTO> ownerList(Page<ArticleDTO> customerPage, ArticleOwnerListReq req) {
        return articleMapper.ownerList(customerPage, req);
    }

    @Override
    public IPage<ArticleGetLikesDTO> getLikeList(Page<ArticleGetLikesDTO> customerPage, Long userId) {
        return articleMapper.getLikeList(customerPage, userId, LIKES_ARTICLE.getBusinessType());
    }

    @Override
    public IPage<ArticleAssociateResp> associatePage(Page<ArticleAssociateResp> customerPage, ArticleAssociateListReq req) {
        return articleMapper.associatePage(customerPage, req);
    }

    @Override
    public List<ArticleStatisticsVO> articleContentTypeStatic(Integer source, Integer auditStatus,Long userId) {
        return articleMapper.articleContentTypeStatic(source,auditStatus,userId);
    }

    /**
     * 品牌专栏-文章分页列表
     *
     * @param customerPage
     * @param req
     * @return
     */
    @Override
    public IPage<ArticleDTO> brandSpecialPage(Page<ArticleDTO> customerPage, ArticleBrandSpecialListReq req) {
        return articleMapper.brandSpecialPage(customerPage, req);
    }

    /**
     * 根据ID，获取对应数据
     *
     * @param objIds
     * @return
     */
    @Override
    @TenantFilter
    public List<ArticleDTO> getArticleByIds(List<Long> objIds,Integer tenantId) {
        return articleMapper.getArticleByIds(objIds,tenantId);
    }
}
